We downloaded data from Census.gov using the get_acs function, did some data wrangling and cleaning, wrote them as a csv file so that we can import them into RMarkdown

#code_folding: "hide" (hides the code but ppl can see the code if they want to)
knitr::opts_chunk$set(echo =  TRUE, warning = FALSE, message = FALSE) #doesn't show the messages or the warings, only code output, must be its in own code chunk to apply to all the subsequent ones
#rent exploitation is another way racial capitalism works to extract resources from the black community, hidden from view, how are these things still operating but are less visible to the average viewer?

#importing data
library(readr)
library(tidycensus)
library(tidyverse)
library(tigris)
library(leaflet)
library(sf)
library(DT)
library(GGally)
library(RColorBrewer)


ACS_Housing_Data <- read_csv("Housing_Data.csv")
Income_By_Tenure <- read_csv("Income_By_Tenure.csv")
Tenure <- read_csv("Tenure.csv")
Tenure_By_Income <- read_csv("Tenure_By_Income.csv")
Tenure_By_Race <- read_csv("Tenurebyrace.csv")
Poverty_By_Race <- read_csv("PovertyByRace.csv")
cvl_rva_measures <- read_csv("cvl_rva_measures.csv")


race <- c("White","Black", "Asian", "Hispanic or Latino")

Basic summary statistics:

How many renters are there in each county? of which demographics?

Petersburg, Hopewell, Charlottesville and Richmond have the highest percentage of renters.

# Tenure <- Tenure[, 3:9]
# Tenure <- full_join(Tenure, Tenure_By_Race, by = "County_fips")

Tenure_By_Race_Perc <- Tenure_By_Race %>% 
  mutate(Perc_rentersE = (RentersE/Total_OccupantsE), Perc_ownersE = (OwnersE/Total_OccupantsE)) %>% 
  group_by(County) %>% 
  summarize(Renters = median(Perc_rentersE, na.rm = TRUE), Owners = median(Perc_ownersE, na.rm = TRUE), White_Renters = median((White_rentersE/RentersE), na.rm = TRUE), White_Owners = median((White_ownersE/OwnersE), na.rm = TRUE), Black_Renters = median((Black_rentersE/RentersE), na.rm = TRUE), Black_Owners = median((Black_ownersE/OwnersE), na.rm = TRUE), NativeAm_Owners = median((NativeAm_ownersE/OwnersE), na.rm = TRUE), NativeAm_Renters = median((NativeAm_rentersE/RentersE), na.rm = TRUE),  Asian_Owners = median((Asian_ownersE/OwnersE), na.rm = TRUE), Asian_Renters = median((Asian_rentersE/RentersE), na.rm = TRUE), PacificIslander_Owners = median((PacificIslander_ownerE/OwnersE), na.rm = TRUE), PacificIslander_Renters = median((PacificIslander_renterE/RentersE), na.rm = TRUE), HispanicLatino_Owners = median((HispanicLatino_ownerE/OwnersE), na.rm = TRUE), HispanicLatino_Renters = median((HispanicLation_renterE/RentersE), na.rm = TRUE)) %>% 
  mutate(across(c(2:14), scales::percent)) %>% 
  arrange(desc(Renters)) %>% 
  select(1:3,4,6,9,11,13,15,5,7,8,10,12,14)


sketch = htmltools::withTags(table(
  class = 'display',
  thead(
    tr(
      th(rowspan = 2, 'County'),
      th(colspan = 6, 'Renters'),
      th(colspan = 6, 'Owners')
    ),
    tr(
      lapply(c('White_Renters', 'Black_Renters', 'NativeAm_Renters', 'Asian_Renters', "PacificIslander_Renters", "HispanicLatino_Renters", 'White_Owners', 'Black_Owners', 'NativeAm_Owners', 'Asian_Owners', "PacificIslander_Owners", "HispanicLatino_Owners"), th)
    )
  )
))

DT_Tenure_By_Race <- Tenure_By_Race_Perc[,c(1,4:15)]

datatable(DT_Tenure_By_Race, 
          caption = htmltools::tags$caption(
            style = 'caption-side: bottom; text-align: center;',
            'Table 1: ', htmltools::em('Median Percentage of Renters and Owners in Each County (by Demographics)')),
          container = sketch, 
          rownames = FALSE, 
          extensions = 'Buttons', 
          options = list(dom='Bfrtip',
                         buttons=c('copy', 'csv', 'excel', 'print', 'pdf')
                         )
          )
#how to make data mpt extend screen and show on next page



#can do a scatterplot matrix and DataTables to provide summary statistics
#maps, leaflets
#models
Tenure_perc_by_race <- Tenure_By_Race %>% 
  mutate(Perc_WRenters = (White_rentersE/RentersE), Perc_WOwners = (White_ownersE/OwnersE), Perc_BRenters = (Black_rentersE/RentersE), Perc_BOwners = (Black_ownersE/OwnersE), Perc_NativeAmOwners = (NativeAm_ownersE/OwnersE), Perc_NativeAmRenters = (NativeAm_rentersE/RentersE),  Perc_AsianOwners = (Asian_ownersE/OwnersE), Perc_AsianRenters = (Asian_rentersE/RentersE), Perc_PacificIslanderOwner = (PacificIslander_ownerE/OwnersE), Perc_PacificIslanderRenter = (PacificIslander_renterE/RentersE), Perc_HispanicLatinoOwner = (HispanicLatino_ownerE/OwnersE), Perc_HispanicLationRenterE = (HispanicLation_renterE/RentersE)) %>%
  select(1:5, 48:59)

Tenure_perc_by_race <- Tenure_perc_by_race %>%
  pivot_longer(., cols = c(Perc_AsianOwners, Perc_WRenters, Perc_WOwners, Perc_BOwners, Perc_BRenters, Perc_NativeAmOwners, Perc_NativeAmRenters, Perc_AsianRenters, Perc_PacificIslanderOwner, Perc_PacificIslanderRenter, Perc_HispanicLatinoOwner, Perc_HispanicLationRenterE), names_to = "Variable", values_to = "Percentage (Estimated)") %>% 
  mutate(Race = case_when(
    str_detect(Variable, "Asian") ~ "Asian",
    str_detect(Variable, "B") ~ "Black",
    str_detect(Variable, "NativeAm") ~ "Native American",
    str_detect(Variable, "PacificIslander") ~ "Pacific Islander",
    str_detect(Variable, "Hispanic") ~ "Hispanic or Latino",
    str_detect(Variable, "WRenters") ~ "White",
    str_detect(Variable, "WOwners") ~ "White"
  ), 
  Variable = case_when(
    str_detect(Variable, "Owner") ~ "Owner",
    str_detect(Variable, "Renter") ~ "Renter"
  )) 


Tenure_perc_by_race <- rename(Tenure_perc_by_race, Tenure_Type = Variable)

# Tenure_perc_by_race$`Percentage (Estimated)` <- round(Tenure_perc_by_race$`Percentage (Estimated)`, 2)
# Tenure_perc_by_race %>% 
#   filter(Tenure_Type == "Renter" & Race %in% race) %>% 
#   ggplot(aes(x = Tenure_Type, y = `Percentage (Estimated)`)) +
#   geom_boxplot() + 
#   facet_wrap(~Race)

#Same graph different output
Tenure_perc_by_race %>% 
  filter(Tenure_Type == "Renter" & Race %in% race ) %>% 
  ggplot(aes(x = Tenure_Type, y = `Percentage (Estimated)`, fill = Race)) +
  scale_fill_viridis_d() +
  geom_boxplot() + 
  facet_wrap(~Region) +
  labs(title = "Racial Composition of Renters in Charlottesville and Richmond, Virginia", x = "Tenure Type")

#Chartlottesville has way less data points

ACS_Housing_Data %>% 
  group_by(Region) %>% 
  summarise(sum = n(), Percent = n()/317)
## # A tibble: 2 × 3
##   Region            sum Percent
##   <chr>           <int>   <dbl>
## 1 Charlottesville    64   0.202
## 2 Richmond          253   0.798
Tenure_perc_by_race %>% 
  filter(Tenure_Type == "Renter") %>% 
  group_by(County, Race) %>% 
  select(4,7,8) %>% 
  summarize(Perc_Renters = median(Tenure_perc_by_race$`Percentage (Estimated)`, na.rm = TRUE)) %>% 
  arrange(desc(Perc_Renters))
## # A tibble: 66 × 3
## # Groups:   County [11]
##    County          Race               Perc_Renters
##    <chr>           <chr>                     <dbl>
##  1 Albemarle       Asian                    0.0119
##  2 Albemarle       Black                    0.0119
##  3 Albemarle       Hispanic or Latino       0.0119
##  4 Albemarle       Native American          0.0119
##  5 Albemarle       Pacific Islander         0.0119
##  6 Albemarle       White                    0.0119
##  7 Charlottesville Asian                    0.0119
##  8 Charlottesville Black                    0.0119
##  9 Charlottesville Hispanic or Latino       0.0119
## 10 Charlottesville Native American          0.0119
## # … with 56 more rows

(backgournd)

relationship between demographics of renters and rent expoitation?

Tenure_and_Housing_Data <- full_join(Tenure_perc_by_race, ACS_Housing_Data, by = "GEOID") %>% 
  select(1,6:30)


Tenure_and_Housing_Data  %>% 
  filter(Tenure_Type == "Renter" & Race %in% race) %>% 
  ggplot(aes(x = `Percentage (Estimated)`, y = RentTaxRatio, color = Region.y)) +
  geom_point(alpha = 0.3) +
  geom_smooth(method = "lm") + 
  facet_wrap(~Race) + 
  labs(title = "Demographic of Renter vs Rent Exploitation in Charlottesville and Richmond, VA", x = "Percentage of Renter (Estimated)", y = "Rent to Tax Ratio", color = "Region") 

# Tenure_and_Housing_Data  %>% 
#   filter(Tenure_Type == "Renter" & Race %in% race) %>% 
#   ggplot(aes(x = `Percentage (Estimated)`, y = RentTaxRatio)) +
#   geom_point(alpha = 0.3) +
#   geom_smooth(method = "lm") + 
#   facet_wrap(~Region.y)

#Before, it was facet_wrapped by race and colored based on the tenure typem but because I filtered out for renters, idk which graph looks better and is "easier" to read and understand, should I remove geom_point, even though she told me to add it?
#modeling whats above


lm1 <- lm(RentTaxRatio ~ `Percentage (Estimated)`:factor(Race), data = Tenure_and_Housing_Data)
lm1 
## 
## Call:
## lm(formula = RentTaxRatio ~ `Percentage (Estimated)`:factor(Race), 
##     data = Tenure_and_Housing_Data)
## 
## Coefficients:
##                                             (Intercept)  
##                                                  0.6365  
##              `Percentage (Estimated)`:factor(Race)Asian  
##                                                 -0.2752  
##              `Percentage (Estimated)`:factor(Race)Black  
##                                                  0.1288  
## `Percentage (Estimated)`:factor(Race)Hispanic or Latino  
##                                                  0.5291  
##    `Percentage (Estimated)`:factor(Race)Native American  
##                                                 -0.2271  
##   `Percentage (Estimated)`:factor(Race)Pacific Islander  
##                                                  2.1519  
##              `Percentage (Estimated)`:factor(Race)White  
##                                                 -0.0360

What is the average rent, income, and real estate taxes paid in each County?

Highest rent: Fluvanna, Chesterfield, Henrico and Albemarle Highest median real estate taxes: Albemare, Charlottesville, Richmond, and Chesterfeild

ACS_Housing_Data |>
  group_by(County) |>
  summarize(Median_rent = median(MedianRentE, na.rm = TRUE), Median_tax = median(MedianTaxesE, na.rm = TRUE), Median_income = median(MedianIncomeE, na.rm = TRUE))
## # A tibble: 11 × 4
##    County          Median_rent Median_tax Median_income
##    <chr>                 <dbl>      <dbl>         <dbl>
##  1 Albemarle             1323       2657         55964 
##  2 Charlottesville       1181       2622.        40104 
##  3 Chesterfield          1333       1935         60040 
##  4 Fluvanna              1419       1786         49581 
##  5 Greene                 974.      1636.        51240.
##  6 Henrico               1214       1923         53133 
##  7 Hopewell               910.      1104.        28625 
##  8 Louisa                 875       1432         46964 
##  9 Nelson                 918.      1357         44754 
## 10 Petersburg City        952       1067         34167 
## 11 Richmond City         1085       2148         37975

Census Tract 4.01 - Friendship Court

Census Tract 6 - Bice House

What is the average rent to tax ratio in each county?

Highest Rent Tax Ratio: Petersburg City, Chesterfeild, and Nelson

ACS_Housing_Data$RentTaxRatio <- round(ACS_Housing_Data$RentTaxRatio, 3)

all<- b <- Tenure_and_Housing_Data %>% 
  filter(`Percentage (Estimated)` >= 0.5, Race == "Black", Tenure_Type == "Renter") %>% 
   group_by(Region.y) %>% 
  summarize(Rent_Tax_RaTio_Black = median(RentTaxRatio, na.rm = TRUE))


b <- Tenure_and_Housing_Data %>% 
  filter(`Percentage (Estimated)` >= 0.5, Race == "Black", Tenure_Type == "Renter") %>% 
   group_by(Region.y) %>% 
  summarize(Rent_Tax_RaTio_Black = median(RentTaxRatio, na.rm = TRUE))
  
all
## # A tibble: 2 × 2
##   Region.y        Rent_Tax_RaTio_Black
##   <chr>                          <dbl>
## 1 Charlottesville                0.962
## 2 Richmond                       0.738
b
## # A tibble: 2 × 2
##   Region.y        Rent_Tax_RaTio_Black
##   <chr>                          <dbl>
## 1 Charlottesville                0.962
## 2 Richmond                       0.738

What is the average percent of rent of income in each county? Thus, which county is the most rent burdened?

Richmond, Charlottesville and Nelson are the most rent burdened counties, but no counties appear to be severly rent burdened (more than 50), on average.

ACS_Housing_Data %>% 
  group_by(County) %>% 
  summarize(Median_perc_rent_income = median(PercRentBurdenE, na.rm = TRUE)) %>% 
  arrange(desc(Median_perc_rent_income))
## # A tibble: 11 × 2
##    County          Median_perc_rent_income
##    <chr>                             <dbl>
##  1 Richmond City                      32.6
##  2 Charlottesville                    31.9
##  3 Hopewell                           31.4
##  4 Henrico                            28.6
##  5 Albemarle                          27.9
##  6 Petersburg City                    27.8
##  7 Chesterfield                       27.5
##  8 Greene                             27  
##  9 Louisa                             26.6
## 10 Nelson                             23.8
## 11 Fluvanna                           21.3

Here is a more detailed look at who’s rent burded and severely rent burdened in each County, with Richmond still being the most rent burdened.

ACS_Housing_Data <- ACS_Housing_Data %>% 
  mutate(Rent_Burdened = case_when(
    PercRentBurdenE >= 30 & PercRentBurdenE < 50  ~ "Yes",
    PercRentBurdenE >= 50 ~"Yes, Severely",
    TRUE ~ "No")
    ) 

Rent_Burden_stats <- ACS_Housing_Data %>% 
  filter(Rent_Burdened != "No") %>% 
  group_by(Rent_Burdened,  County) %>% 
  summarize(Percent = round((n()/317)*100, 3)) %>% 
  arrange(desc(Percent))

knitr::kable(Rent_Burden_stats)
Rent_Burdened County Percent
Yes Richmond City 13.565
Yes Henrico 10.095
Yes Chesterfield 6.940
Yes Albemarle 3.155
Yes Charlottesville 2.208
Yes Petersburg City 1.262
Yes, Severely Richmond City 1.262
Yes Hopewell 0.946
Yes Louisa 0.946
Yes, Severely Chesterfield 0.946
Yes, Severely Albemarle 0.315
Yes, Severely Fluvanna 0.315
Yes, Severely Henrico 0.315
Yes, Severely Nelson 0.315

As we can see here, alhtough it may not look like it from the numbers above, a lot of counties (the biggest census tracts too) are rent burdened, some even severely.

counties <- c("Albemarle", "Charlottesville", "Fluvanna", "Greene", "Louisa", "Nelson", "Richmond city", "Henrico", "Chesterfield", "Hopewell", "Petersburg")
countytracts <- tracts(state = "VA", county = counties, year = 2020)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=======                                                               |  11%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |================                                                      |  24%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=====================                                                 |  31%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=======================                                               |  34%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |========================================================              |  81%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |==========================================================            |  84%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |=================================================================     |  94%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%
countytracts <- countytracts |>
  mutate(GEOID = as.numeric(countytracts$GEOID)) 

HousingDataSpatial <- full_join(ACS_Housing_Data, countytracts, by = "GEOID") |>
  sf::st_as_sf() |>
  mutate(INTPTLAT = as.numeric(countytracts$INTPTLAT), INTPTLON = as.numeric(countytracts$INTPTLON))|> 
   sf::st_transform(crs = '+proj=longlat +datum=WGS84') #one way to reference a CRS, another way (which Claibourne used) is cvl_rents <- st_transform(cvl_rents, 4326) because leaflet expects the crs to be 4326


pal <-  colorNumeric("YlOrRd", HousingDataSpatial$PercRentBurdenE, reverse = TRUE)

HousingDataSpatial %>% 
leaflet() %>% 
  addTiles() %>% 
  addPolygons(color = "black",
              fillColor = ~pal(PercRentBurdenE),
              fillOpacity = 0.6,
              weight = 2,
              highlight = highlightOptions(
                weight = 3,
                fillOpacity = 0.9,
                bringToFront = T),
              popup = paste0("County: ", HousingDataSpatial$County, "<br>",
                             "Tract: ", HousingDataSpatial$NAMELSAD, "<br>",
                             "Percentage of Rent Burden: ", HousingDataSpatial$PercRentBurdenE)) %>% 
  addLegend(pal = pal, 
            values = ~PercRentBurdenE, 
            opacity = 0.7, 
            title = "Percentage of Rent Burden (2020)", 
            position = "bottomleft")
#FOR POSTER
HousingDataSpatial %>% 
  filter(Region == "Charlottesville") %>% 
  ggplot() + 
  geom_sf(aes(fill=PercRentBurdenE)) +
  scale_fill_viridis_c() +
  scale_color_viridis_c() +
  ggtitle("Degree of Rent Burden in Charlottesville", subtitle = "2020 ACS") +
  labs(fill = "Rent as a Percentage of Household Income")

Rent_Burden_rvl_sf <- HousingDataSpatial %>% 
  filter(Region == "Richmond") %>% 
  ggplot() + 
  geom_sf(aes(fill=PercRentBurdenE)) +
  scale_fill_viridis_c() +
  scale_color_viridis_c() +
  ggtitle("Degree of Rent Burden in Richmond", subtitle = "2020 ACS") +
  labs(fill = "Rent as a Percentage of Household Income")


ggsave("Degree of Rent Burden in Richmond.png", Rent_Burden_rvl_sf)


Rent_Burdened_Stats_Detailed <- HousingDataSpatial %>% 
  filter(PercRentBurdenE >= 30) %>% 
  select(3,12) %>% 
  arrange(desc(PercRentBurdenE))

knitr::kable(Rent_Burdened_Stats_Detailed)
NAME.x PercRentBurdenE geometry
Census Tract 1002.08, Chesterfield County, Virginia 51.0 MULTIPOLYGON (((-77.59176 3…
Census Tract 1009.07, Chesterfield County, Virginia 51.0 MULTIPOLYGON (((-77.58165 3…
Census Tract 1010.03, Chesterfield County, Virginia 51.0 MULTIPOLYGON (((-77.87842 3…
Census Tract 9501.02, Nelson County, Virginia 51.0 MULTIPOLYGON (((-78.90884 3…
Census Tract 210, Richmond city, Virginia 51.0 MULTIPOLYGON (((-77.40362 3…
Census Tract 305.01, Richmond city, Virginia 51.0 MULTIPOLYGON (((-77.44895 3…
Census Tract 403, Richmond city, Virginia 51.0 MULTIPOLYGON (((-77.45652 3…
Census Tract 201.03, Fluvanna County, Virginia 51.0 MULTIPOLYGON (((-78.34287 3…
Census Tract 710.04, Richmond city, Virginia 51.0 MULTIPOLYGON (((-77.52794 3…
Census Tract 105.01, Albemarle County, Virginia 51.0 MULTIPOLYGON (((-78.45505 3…
Census Tract 2015.04, Henrico County, Virginia 51.0 MULTIPOLYGON (((-77.39592 3…
Census Tract 302, Richmond city, Virginia 48.9 MULTIPOLYGON (((-77.44727 3…
Census Tract 2.02, Charlottesville city, Virginia 48.6 MULTIPOLYGON (((-78.50342 3…
Census Tract 404, Richmond city, Virginia 48.3 MULTIPOLYGON (((-77.46265 3…
Census Tract 2001.24, Henrico County, Virginia 48.3 MULTIPOLYGON (((-77.63887 3…
Census Tract 6, Charlottesville city, Virginia 47.8 MULTIPOLYGON (((-78.52363 3…
Census Tract 504, Richmond city, Virginia 47.5 MULTIPOLYGON (((-77.51961 3…
Census Tract 212, Richmond city, Virginia 47.1 MULTIPOLYGON (((-77.40902 3…
Census Tract 1004.06, Chesterfield County, Virginia 46.7 MULTIPOLYGON (((-77.45375 3…
Census Tract 203, Richmond city, Virginia 46.3 MULTIPOLYGON (((-77.41706 3…
Census Tract 402.01, Richmond city, Virginia 46.0 MULTIPOLYGON (((-77.45534 3…
Census Tract 2016.02, Henrico County, Virginia 45.9 MULTIPOLYGON (((-77.42901 3…
Census Tract 106.04, Albemarle County, Virginia 45.3 MULTIPOLYGON (((-78.47379 3…
Census Tract 9505, Louisa County, Virginia 44.6 MULTIPOLYGON (((-77.89289 3…
Census Tract 708.03, Richmond city, Virginia 44.0 MULTIPOLYGON (((-77.5042 37…
Census Tract 8104, Petersburg city, Virginia 43.1 MULTIPOLYGON (((-77.43129 3…
Census Tract 9501.02, Louisa County, Virginia 43.0 MULTIPOLYGON (((-77.95314 3…
Census Tract 2010.02, Henrico County, Virginia 42.6 MULTIPOLYGON (((-77.41507 3…
Census Tract 110, Richmond city, Virginia 41.8 MULTIPOLYGON (((-77.43683 3…
Census Tract 604, Richmond city, Virginia 41.8 MULTIPOLYGON (((-77.48407 3…
Census Tract 2006, Henrico County, Virginia 41.8 MULTIPOLYGON (((-77.48872 3…
Census Tract 8204, Hopewell city, Virginia 41.5 MULTIPOLYGON (((-77.33777 3…
Census Tract 1004.10, Chesterfield County, Virginia 41.2 MULTIPOLYGON (((-77.46391 3…
Census Tract 104.02, Richmond city, Virginia 41.2 MULTIPOLYGON (((-77.46287 3…
Census Tract 2011.04, Henrico County, Virginia 41.2 MULTIPOLYGON (((-77.39581 3…
Census Tract 608, Richmond city, Virginia 41.1 MULTIPOLYGON (((-77.44863 3…
Census Tract 2001.22, Henrico County, Virginia 41.1 MULTIPOLYGON (((-77.63849 3…
Census Tract 2007, Henrico County, Virginia 40.9 MULTIPOLYGON (((-77.47378 3…
Census Tract 1010.14, Chesterfield County, Virginia 40.5 MULTIPOLYGON (((-77.67324 3…
Census Tract 602, Richmond city, Virginia 40.5 MULTIPOLYGON (((-77.44793 3…
Census Tract 7, Charlottesville city, Virginia 39.9 MULTIPOLYGON (((-78.51737 3…
Census Tract 2010.03, Henrico County, Virginia 39.3 MULTIPOLYGON (((-77.41168 3…
Census Tract 1002.12, Chesterfield County, Virginia 39.0 MULTIPOLYGON (((-77.51638 3…
Census Tract 5.01, Charlottesville city, Virginia 38.8 MULTIPOLYGON (((-78.50552 3…
Census Tract 2011.03, Henrico County, Virginia 38.8 MULTIPOLYGON (((-77.37542 3…
Census Tract 2009.04, Henrico County, Virginia 38.7 MULTIPOLYGON (((-77.45269 3…
Census Tract 1003, Chesterfield County, Virginia 38.5 MULTIPOLYGON (((-77.46161 3…
Census Tract 8105, Petersburg city, Virginia 38.0 MULTIPOLYGON (((-77.44586 3…
Census Tract 108, Richmond city, Virginia 37.9 MULTIPOLYGON (((-77.42816 3…
Census Tract 1009.35, Chesterfield County, Virginia 37.5 MULTIPOLYGON (((-77.6769 37…
Census Tract 109.04, Albemarle County, Virginia 37.5 MULTIPOLYGON (((-78.52864 3…
Census Tract 102.02, Richmond city, Virginia 37.4 MULTIPOLYGON (((-77.47942 3…
Census Tract 610.01, Richmond city, Virginia 37.4 MULTIPOLYGON (((-77.46167 3…
Census Tract 1008.06, Chesterfield County, Virginia 37.1 MULTIPOLYGON (((-77.47331 3…
Census Tract 2008.07, Henrico County, Virginia 37.0 MULTIPOLYGON (((-77.44934 3…
Census Tract 201, Richmond city, Virginia 36.9 MULTIPOLYGON (((-77.4277 37…
Census Tract 111.01, Albemarle County, Virginia 36.9 MULTIPOLYGON (((-78.72575 3…
Census Tract 2.01, Charlottesville city, Virginia 36.7 MULTIPOLYGON (((-78.50044 3…
Census Tract 605.02, Richmond city, Virginia 36.5 MULTIPOLYGON (((-77.49326 3…
Census Tract 2004.09, Henrico County, Virginia 36.5 MULTIPOLYGON (((-77.53545 3…
Census Tract 2004.15, Henrico County, Virginia 36.4 MULTIPOLYGON (((-77.54265 3…
Census Tract 1005.06, Chesterfield County, Virginia 36.2 MULTIPOLYGON (((-77.44617 3…
Census Tract 708.02, Richmond city, Virginia 36.1 MULTIPOLYGON (((-77.48902 3…
Census Tract 2004.13, Henrico County, Virginia 35.8 MULTIPOLYGON (((-77.54721 3…
Census Tract 109.01, Albemarle County, Virginia 35.7 MULTIPOLYGON (((-78.52472 3…
Census Tract 111, Richmond city, Virginia 35.6 MULTIPOLYGON (((-77.45443 3…
Census Tract 2003.05, Henrico County, Virginia 35.5 MULTIPOLYGON (((-77.55384 3…
Census Tract 1005.07, Chesterfield County, Virginia 35.4 MULTIPOLYGON (((-77.46006 3…
Census Tract 2004.18, Henrico County, Virginia 35.4 MULTIPOLYGON (((-77.5242 37…
Census Tract 2014.03, Henrico County, Virginia 35.3 MULTIPOLYGON (((-77.31943 3…
Census Tract 208, Richmond city, Virginia 35.0 MULTIPOLYGON (((-77.41925 3…
Census Tract 108.02, Albemarle County, Virginia 34.9 MULTIPOLYGON (((-78.53369 3…
Census Tract 1008.17, Chesterfield County, Virginia 34.8 MULTIPOLYGON (((-77.51583 3…
Census Tract 105, Richmond city, Virginia 34.8 MULTIPOLYGON (((-77.44418 3…
Census Tract 204, Richmond city, Virginia 34.8 MULTIPOLYGON (((-77.43291 3…
Census Tract 106.03, Albemarle County, Virginia 34.8 MULTIPOLYGON (((-78.48515 3…
Census Tract 710.02, Richmond city, Virginia 34.6 MULTIPOLYGON (((-77.51603 3…
Census Tract 2004.12, Henrico County, Virginia 34.5 MULTIPOLYGON (((-77.52945 3…
Census Tract 1009.12, Chesterfield County, Virginia 34.4 MULTIPOLYGON (((-77.6916 37…
Census Tract 8101, Petersburg city, Virginia 34.4 MULTIPOLYGON (((-77.39573 3…
Census Tract 8207, Hopewell city, Virginia 34.3 MULTIPOLYGON (((-77.29925 3…
Census Tract 2012.05, Henrico County, Virginia 34.3 MULTIPOLYGON (((-77.34449 3…
Census Tract 8205, Hopewell city, Virginia 34.2 MULTIPOLYGON (((-77.31972 3…
Census Tract 707, Richmond city, Virginia 34.2 MULTIPOLYGON (((-77.52381 3…
Census Tract 709.01, Richmond city, Virginia 34.2 MULTIPOLYGON (((-77.47859 3…
Census Tract 103, Richmond city, Virginia 34.0 MULTIPOLYGON (((-77.4492 37…
Census Tract 2001.06, Henrico County, Virginia 33.9 MULTIPOLYGON (((-77.59446 3…
Census Tract 2001.36, Henrico County, Virginia 33.9 MULTIPOLYGON (((-77.64026 3…
Census Tract 501, Richmond city, Virginia 33.6 MULTIPOLYGON (((-77.49483 3…
Census Tract 107.01, Albemarle County, Virginia 33.6 MULTIPOLYGON (((-78.49932 3…
Census Tract 2001.38, Henrico County, Virginia 33.6 MULTIPOLYGON (((-77.6074 37…
Census Tract 8106, Petersburg city, Virginia 33.4 MULTIPOLYGON (((-77.42329 3…
Census Tract 106, Richmond city, Virginia 33.2 MULTIPOLYGON (((-77.45496 3…
Census Tract 710.03, Richmond city, Virginia 33.1 MULTIPOLYGON (((-77.52287 3…
Census Tract 104.01, Richmond city, Virginia 33.0 MULTIPOLYGON (((-77.46416 3…
Census Tract 706.02, Richmond city, Virginia 33.0 MULTIPOLYGON (((-77.48872 3…
Census Tract 505, Richmond city, Virginia 32.8 MULTIPOLYGON (((-77.54733 3…
Census Tract 103.02, Albemarle County, Virginia 32.8 MULTIPOLYGON (((-78.46114 3…
Census Tract 109, Richmond city, Virginia 32.7 MULTIPOLYGON (((-77.43092 3…
Census Tract 1006, Chesterfield County, Virginia 32.6 MULTIPOLYGON (((-77.43459 3…
Census Tract 4.01, Charlottesville city, Virginia 32.5 MULTIPOLYGON (((-78.50536 3…
Census Tract 703, Richmond city, Virginia 32.5 MULTIPOLYGON (((-77.55451 3…
Census Tract 2014.06, Henrico County, Virginia 32.5 MULTIPOLYGON (((-77.36603 3…
Census Tract 206, Richmond city, Virginia 32.3 MULTIPOLYGON (((-77.4214 37…
Census Tract 1005.05, Chesterfield County, Virginia 32.2 MULTIPOLYGON (((-77.47154 3…
Census Tract 1009.26, Chesterfield County, Virginia 32.1 MULTIPOLYGON (((-77.66533 3…
Census Tract 708.04, Richmond city, Virginia 32.1 MULTIPOLYGON (((-77.51436 3…
Census Tract 207, Richmond city, Virginia 31.9 MULTIPOLYGON (((-77.4182 37…
Census Tract 2008.01, Henrico County, Virginia 31.9 MULTIPOLYGON (((-77.49403 3…
Census Tract 2008.05, Henrico County, Virginia 31.9 MULTIPOLYGON (((-77.44088 3…
Census Tract 1001.07, Chesterfield County, Virginia 31.7 MULTIPOLYGON (((-77.54964 3…
Census Tract 1008.14, Chesterfield County, Virginia 31.7 MULTIPOLYGON (((-77.51504 3…
Census Tract 413, Richmond city, Virginia 31.7 MULTIPOLYGON (((-77.48373 3…
Census Tract 112.01, Albemarle County, Virginia 31.6 MULTIPOLYGON (((-78.83701 3…
Census Tract 1009.28, Chesterfield County, Virginia 31.5 MULTIPOLYGON (((-77.71673 3…
Census Tract 102.01, Richmond city, Virginia 31.5 MULTIPOLYGON (((-77.4669 37…
Census Tract 9502.01, Louisa County, Virginia 31.4 MULTIPOLYGON (((-78.09412 3…
Census Tract 2001.31, Henrico County, Virginia 31.4 MULTIPOLYGON (((-77.55244 3…
Census Tract 2001.52, Henrico County, Virginia 31.4 MULTIPOLYGON (((-77.57421 3…
Census Tract 4.02, Charlottesville city, Virginia 31.3 MULTIPOLYGON (((-78.48534 3…
Census Tract 605.01, Richmond city, Virginia 31.3 MULTIPOLYGON (((-77.47312 3…
Census Tract 209, Richmond city, Virginia 31.2 MULTIPOLYGON (((-77.41071 3…
Census Tract 1002.11, Chesterfield County, Virginia 30.8 MULTIPOLYGON (((-77.52517 3…
Census Tract 2001.53, Henrico County, Virginia 30.8 MULTIPOLYGON (((-77.57858 3…
Census Tract 2005.01, Henrico County, Virginia 30.8 MULTIPOLYGON (((-77.51625 3…
Census Tract 2017.01, Henrico County, Virginia 30.6 MULTIPOLYGON (((-77.32844 3…
Census Tract 414, Richmond city, Virginia 30.5 MULTIPOLYGON (((-77.47557 3…
Census Tract 2004.07, Henrico County, Virginia 30.5 MULTIPOLYGON (((-77.5605 37…
Census Tract 105.02, Albemarle County, Virginia 30.4 MULTIPOLYGON (((-78.46098 3…
Census Tract 211, Richmond city, Virginia 30.3 MULTIPOLYGON (((-77.41932 3…
Census Tract 1005.09, Chesterfield County, Virginia 30.2 MULTIPOLYGON (((-77.40572 3…
Census Tract 1008.12, Chesterfield County, Virginia 30.1 MULTIPOLYGON (((-77.59442 3…
Census Tract 1009.29, Chesterfield County, Virginia 30.1 MULTIPOLYGON (((-77.65963 3…
Census Tract 2005.03, Henrico County, Virginia 30.1 MULTIPOLYGON (((-77.5181 37…
Census Tract 1004.05, Chesterfield County, Virginia 30.0 MULTIPOLYGON (((-77.45335 3…

relationship between demographics of renters and being rent burndened?

# 
# Tenure_and_Housing_Data  %>% 
#   filter(Tenure_Type == "Renter") %>% 
#   ggplot(aes(x = `Percentage (Estimated)`, y = PercRentBurdenE, color = Tenure_Type)) +
#   geom_point(alpha = 0.3) +
#   geom_smooth(method = "lm") + 
#   facet_wrap(~Race)


#different graph, same 

Tenure_and_Housing_Data  %>% 
  filter(Tenure_Type == "Renter" & Race %in% race) %>% 
  ggplot(aes(x = `Percentage (Estimated)`, y = PercRentBurdenE, color = Region.y)) +
  scale_color_viridis_d() +
  geom_point(alpha = 0.3) +
  geom_smooth(method = "lm") + 
  facet_wrap(~Race) +
  labs(title = "Demographic of Renter vs Rent Burden in CVL and RVA", x = "Percentage of Renter (Estimated)", y = "Rent as a Percentage of Income", color = "Region")

#model whats above



lm3 <- lm(PercRentBurdenE ~ Race:`Percentage (Estimated)`, data = Tenure_and_Housing_Data)
lm3
## 
## Call:
## lm(formula = PercRentBurdenE ~ Race:`Percentage (Estimated)`, 
##     data = Tenure_and_Housing_Data)
## 
## Coefficients:
##                                     (Intercept)  
##                                          30.431  
##              RaceAsian:`Percentage (Estimated)`  
##                                          -3.197  
##              RaceBlack:`Percentage (Estimated)`  
##                                           3.336  
## RaceHispanic or Latino:`Percentage (Estimated)`  
##                                           4.721  
##    RaceNative American:`Percentage (Estimated)`  
##                                          44.182  
##   RacePacific Islander:`Percentage (Estimated)`  
##                                         -46.827  
##              RaceWhite:`Percentage (Estimated)`  
##                                          -1.090
#relationship btw those who are rent burdened and rent tax ratio?
Tenure_and_Housing_Data %>% 
ggplot(aes(x = PercRentBurdenE, y = RentTaxRatio)) + 
  geom_point(alpha = 0.3) +
    geom_smooth(method = "lm") +
  facet_wrap(~Region.y)

#model whats above

lm5 <- lm(RentTaxRatio ~ PercRentBurdenE, data = Tenure_and_Housing_Data)
lm5
## 
## Call:
## lm(formula = RentTaxRatio ~ PercRentBurdenE, data = Tenure_and_Housing_Data)
## 
## Coefficients:
##     (Intercept)  PercRentBurdenE  
##        0.572868         0.002289

What does the income and ratio look like there?

Although these three are the most rent burdened, it isn’t obvious based on its rent to tax ratio and median household income, except for in Nelson county (which only has 5 observations in the tract)

  1. Richmond: Median Income is $53,216.5 and the Rent to Tax Ratio is 0.484
  2. Charlottesville: Median Income is $62,477.5 and the Rent to Tax Ratio is 0.4325
  3. Nelson: Median Income is $53,579 and the Rent to Tax Ratio is 0.71

How many are below the poverty level in this County? and which demographics?

We can reach the same conclusions here, with Richmond having the third highest percentage of those below the poverty level.

  1. Richmond: On average, 17.6% of the county is below the poverty level and people who are Black and Asian have the highest average percent of those below the poverty level.
  2. Charlottesville: On average, 15.3% of the county is below the poverty level and people who are Hispanic or Latino and Asian have the highest average percent of those below the poverty level.
  3. Nelson: On average, 12.9% of the county is below the poverty level and people who are Asian have the highest average percent of those below the poverty level (50%).

What is the income distribution in this census tract look like?

Which county has the most students (includes Undergraduate and Graduate students)?

No one county has a disproportionate amount of students compared to the other, however, Richmond, Charlottesville, and Henrico have the highest student populations

 ACS_Housing_Data %>% 
  group_by(County) %>% 
  summarize(Median_perc_students = median(Perc_StudentsE, na.rm = TRUE))
## # A tibble: 11 × 2
##    County          Median_perc_students
##    <chr>                          <dbl>
##  1 Albemarle                       5.21
##  2 Charlottesville                 5.98
##  3 Chesterfield                    5.43
##  4 Fluvanna                        4.96
##  5 Greene                          3.16
##  6 Henrico                         5.59
##  7 Hopewell                        4.84
##  8 Louisa                          3.7 
##  9 Nelson                          4.96
## 10 Petersburg City                 4.8 
## 11 Richmond City                   6.59

*More than 50% of pop. in tracts in Richmond and Charlottesville city consist of students, but doesn’t seem like the case for Henrico!

##Students

#pal1 <- colorNumeric("Greens", domain = HousingDataSpatial$County, HousingDataSpatial$County)

#creating map and adding layers

perc_student_counties <- c("Richmond City", "Charlottesville", "Henrico")

Moststudents <- HousingDataSpatial %>% 
  filter(County %in% perc_student_counties)

pal1 <-  colorNumeric("YlOrRd", Moststudents$Perc_StudentsE, reverse = TRUE) #the reverse argument reverses the color palette 


Moststudents %>% 
  leaflet() %>% 
  addTiles() %>% 
  addPolygons(color = "black",
              fillColor = ~pal1(Perc_StudentsE),
              weight = 2,
              fillOpacity = 0.6,
              highlight = highlightOptions(
                weight = 3,
                fillOpacity = 0.9,
                bringToFront = T),
              popup = paste0("County: ", Moststudents$County, "<br>",
                             "Tract: ", Moststudents$NAMELSAD, "<br>",
                             "Percentage of Rent Burden: ", Moststudents$Perc_StudentsE)) %>% #to add hovering functionality check what she put for the highlight argument and to add popups, check what she put for the popup argument
  addLegend(pal = pal1, 
            values = ~Perc_StudentsE, 
            opacity = 0.7, 
            title = "Highest Percentage of Students in Charlottesville and Richmond regions for 2020", 
            position = "bottomleft")
HousingDataSpatial %>% 
  filter(Perc_StudentsE >= 50) %>% 
  select(3,22) %>% 
  arrange(desc(Perc_StudentsE))
## Simple feature collection with 8 features and 2 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -78.52874 ymin: 37.22587 xmax: -77.41441 ymax: 38.05642
## CRS:           +proj=longlat +datum=WGS84
## # A tibble: 8 × 3
##   NAME.x                                Perc_StudentsE                  geometry
##   <chr>                                          <dbl>        <MULTIPOLYGON [°]>
## 1 Census Tract 403, Richmond city, Vir…           90.5 (((-77.45652 37.54333, -…
## 2 Census Tract 109.04, Albemarle Count…           86.5 (((-78.52864 38.02705, -…
## 3 Census Tract 6, Charlottesville city…           71.9 (((-78.52363 38.0224, -7…
## 4 Census Tract 402.01, Richmond city, …           68.8 (((-77.45534 37.55372, -…
## 5 Census Tract 109.01, Albemarle Count…           65.9 (((-78.52472 38.0483, -7…
## 6 Census Tract 2.02, Charlottesville c…           60.4 (((-78.50342 38.03681, -…
## 7 Census Tract 1006, Chesterfield Coun…           60.4 (((-77.43459 37.23137, -…
## 8 Census Tract 305.01, Richmond city, …           54.9 (((-77.44895 37.54312, -…
#ask soumya/claibourne why census tracts that aren't shaded ar being shown (esp since I filtered the dataframe)


#Tabset


###heading 1{.tabset}

####every heading under is a tabset!
#Can make the first tabs a leaflet and the third one as a scatterplot 

*Can see that Henrico Coutny has quite a few tracts with more than 10% of students and one with more than 15%, but it doesn’t compare to the major cities in VA

HousingDataSpatial %>% 
  filter(County == "Henrico") %>% 
  ggplot(aes(x = NAME.y, y = Perc_StudentsE)) + 
  geom_col() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

What does the income, and ratio look like there?

  1. Richmond: Median Income is $53,216.5 and the Rent to Tax Ratio is 0.484
  2. Charlottesville: Median Income is $62,477.5 and the Rent to Tax Ratio is 0.433
  3. Henrico: Median Income is $69,827 and the Rent to Tax Ratio is 0.659

How does this compare to the average gini index and who’s below poverty in each county?

Poverty_By_Race %>% 
  group_by(County) %>% 
  summarize(Median_perc_below_poverty = median(Perc_Total_BelowPovertyE, na.rm = TRUE), Median_Gini_Index = median(Gini_IndexE, na.rm = TRUE))
## # A tibble: 11 × 3
##    County          Median_perc_below_poverty Median_Gini_Index
##    <chr>                               <dbl>             <dbl>
##  1 Albemarle                            5.71             0.428
##  2 Charlottesville                     15.3              0.480
##  3 Chesterfield                         5.39             0.356
##  4 Fluvanna                             3.76             0.407
##  5 Greene                               9.22             0.390
##  6 Henrico                              7.54             0.394
##  7 Hopewell                            27.8              0.439
##  8 Louisa                              10.6              0.426
##  9 Nelson                              12.9              0.452
## 10 Petersburg City                     22.1              0.437
## 11 Richmond City                       17.7              0.448
Poverty_Stats <- Poverty_By_Race %>% 
  filter(Gini_IndexE >= 0.5 & Perc_Total_BelowPovertyE >= 0.5) %>% 
  select(3,4,36,50) %>% 
  arrange(desc(Gini_IndexE))

knitr::kable(Poverty_Stats)
NAME County Gini_IndexE Perc_Total_BelowPovertyE
Census Tract 201.03, Fluvanna County, Virginia Fluvanna 0.7173 6.53
Census Tract 403, Richmond city, Virginia Richmond City 0.7044 66.57
Census Tract 305.01, Richmond city, Virginia Richmond City 0.6917 58.62
Census Tract 6, Charlottesville city, Virginia Charlottesville 0.6686 63.91
Census Tract 404, Richmond city, Virginia Richmond City 0.6400 39.70
Census Tract 207, Richmond city, Virginia Richmond City 0.6393 21.24
Census Tract 7, Charlottesville city, Virginia Charlottesville 0.6153 21.08
Census Tract 2008.05, Henrico County, Virginia Henrico 0.6129 32.49
Census Tract 1009.38, Chesterfield County, Virginia Chesterfield 0.6044 0.79
Census Tract 9501.02, Nelson County, Virginia Nelson 0.5953 17.73
Census Tract 2009.08, Henrico County, Virginia Henrico 0.5929 8.58
Census Tract 405, Richmond city, Virginia Richmond City 0.5811 14.40
Census Tract 104.01, Albemarle County, Virginia Albemarle 0.5762 5.29
Census Tract 210, Richmond city, Virginia Richmond City 0.5745 30.86
Census Tract 204, Richmond city, Virginia Richmond City 0.5731 50.49
Census Tract 8107, Petersburg city, Virginia Petersburg City 0.5605 22.63
Census Tract 413, Richmond city, Virginia Richmond City 0.5551 17.66
Census Tract 2.02, Charlottesville city, Virginia Charlottesville 0.5448 57.51
Census Tract 109.01, Albemarle County, Virginia Albemarle 0.5433 29.63
Census Tract 412, Richmond city, Virginia Richmond City 0.5417 32.50
Census Tract 109.04, Albemarle County, Virginia Albemarle 0.5407 29.15
Census Tract 4.01, Charlottesville city, Virginia Charlottesville 0.5317 18.69
Census Tract 209, Richmond city, Virginia Richmond City 0.5309 8.30
Census Tract 710.04, Richmond city, Virginia Richmond City 0.5306 50.90
Census Tract 2010.03, Henrico County, Virginia Henrico 0.5291 18.17
Census Tract 505, Richmond city, Virginia Richmond City 0.5284 2.57
Census Tract 605.02, Richmond city, Virginia Richmond City 0.5225 8.58
Census Tract 10, Charlottesville city, Virginia Charlottesville 0.5205 7.69
Census Tract 101, Albemarle County, Virginia Albemarle 0.5178 6.29
Census Tract 1009.26, Chesterfield County, Virginia Chesterfield 0.5125 1.94
Census Tract 501, Richmond city, Virginia Richmond City 0.5099 8.22
Census Tract 112.01, Albemarle County, Virginia Albemarle 0.5060 6.02
Census Tract 8106, Petersburg city, Virginia Petersburg City 0.5018 36.43
Census Tract 102.01, Richmond city, Virginia Richmond City 0.5017 7.02
Census Tract 8113, Petersburg city, Virginia Petersburg City 0.5014 34.61
Census Tract 109, Richmond city, Virginia Richmond City 0.5013 21.20
Poverty_By_Race %>% 
  ggplot(aes(x = Perc_Total_BelowPovertyE, y = Gini_IndexE)) +
  geom_point(alpha = 0.3) +
  geom_smooth(method = "lm") +
  facet_wrap(~Region)

#model 

lm(Gini_IndexE ~ Perc_Total_BelowPovertyE, data = Poverty_By_Race)
## 
## Call:
## lm(formula = Gini_IndexE ~ Perc_Total_BelowPovertyE, data = Poverty_By_Race)
## 
## Coefficients:
##              (Intercept)  Perc_Total_BelowPovertyE  
##                  0.38135                   0.00279
lm(Perc_Total_BelowPovertyE ~ Gini_IndexE, data = Poverty_By_Race)
## 
## Call:
## lm(formula = Perc_Total_BelowPovertyE ~ Gini_IndexE, data = Poverty_By_Race)
## 
## Coefficients:
## (Intercept)  Gini_IndexE  
##      -17.26        72.31

Which demographics are most likely to be below poverty and above (or at) in each county?

PovertyBy_Race_County <- Poverty_By_Race %>% 
  group_by(County) %>% 
  summarize(Median_Perc_WBelowPoverty = median((Perc_BelowPoverty_WhiteE), na.rm = TRUE), Median_Perc_BBelowPoverty = median((Perc_BelowPoverty_BlackE), na.rm = TRUE), Median_Perc_NativeAm_BelowPoverty = median((Perc_BelowPoverty_NativeAmE), na.rm = TRUE),  Median_Perc_Asian_BelowPoverty = median((Perc_BelowPoverty_AsianE), na.rm = TRUE), Median_Perc_PacificIslander_BelowPoverty = median((Perc_BelowPoverty_PacificIslanderE), na.rm = TRUE), Median_Perc_HispanicLatino_BelowPoverty = median((Perc_BelowPoverty_HispanicLatinoE), na.rm = TRUE))

knitr::kable(PovertyBy_Race_County)
County Median_Perc_WBelowPoverty Median_Perc_BBelowPoverty Median_Perc_NativeAm_BelowPoverty Median_Perc_Asian_BelowPoverty Median_Perc_PacificIslander_BelowPoverty Median_Perc_HispanicLatino_BelowPoverty
Albemarle 5.670 0.840 0.00 0.00 0 0.460
Charlottesville 11.020 14.575 0.00 19.48 0 17.900
Chesterfield 4.140 5.320 0.00 0.00 0 4.420
Fluvanna 3.730 3.690 0.00 0.00 0 0.000
Greene 6.595 9.340 0.00 2.38 NA 8.390
Henrico 5.860 7.080 0.00 0.00 0 0.865
Hopewell 20.820 33.050 0.00 0.00 NA 30.635
Louisa 9.000 20.730 0.00 0.00 NA 0.000
Nelson 4.500 2.750 NA 50.00 NA 0.000
Petersburg City 12.140 23.000 47.22 8.74 0 1.780
Richmond City 9.200 24.690 0.00 26.92 0 12.545
#graph!            

#Relationship btw those who are rent burdended and gini index?

#Scatterplot Matrix

# 
# 
# pbr_matrix <- ggpairs(Poverty_By_Race, mapping = aes(color = Region), columns = c(38, 39, 40, 43, 50, 36))
# 
# pbr_matrix
#
 HDSpatial_Updated <- HousingDataSpatial %>%
   mutate(county_tract = paste(COUNTYFP,TRACTCE, sep = "")) 
#
 cvl_rva_measures_Spatial <- full_join(cvl_rva_measures, HDSpatial_Updated, by = "county_tract") %>%
   sf::st_as_sf() |>
   sf::st_transform(crs = 4326)
#
pal2 <-  colorNumeric("viridis", cvl_rva_measures_Spatial$iso_b_block, reverse = TRUE)

cvl_rva_measures_Spatial %>%
 leaflet() %>%
   addTiles() %>%
   addPolygons(color = "black",
               fillColor = ~pal2(iso_b_block),
               fillOpacity = 0.6,
               weight = 2,
               highlight = highlightOptions(
                 weight = 3,
                 fillOpacity = 0.9,
                 bringToFront = T),
               popup = paste0("County: ", cvl_rva_measures_Spatial$County, "<br>",
                              "Tract: ", cvl_rva_measures_Spatial$NAME.x, "<br>",
                              "Isolation Index: ", cvl_rva_measures_Spatial$iso_b_block)) %>%
  addLegend(pal = pal2,
             values = ~iso_b_block,
             opacity = 0.7,
            title = "Black Isolation Index (2020)",
             position = "bottomleft")
# Code above not working, all appearing as the same color...



#FOR THE POSTER
Iso_index_cvl_rva <- cvl_rva_measures_Spatial %>% 
  ggplot() + 
  geom_sf(aes(fill=iso_b_block)) +
  scale_fill_viridis_c() +
  scale_color_viridis_c() +
  ggtitle("Black Isolation Index in Charlottesville and Richmond, VA", subtitle = "Data from the 2020 American Community Survey (ACS)") +
  labs(fill = "Isolation Index")

Iso_index_rva <- cvl_rva_measures_Spatial %>%
  filter(Region == "Richmond") %>% 
  ggplot() + 
  geom_sf(aes(fill=iso_b_block)) +
  scale_fill_viridis_c() +
  scale_color_viridis_c() +
  ggtitle("Black Isolation Index in Richomond", subtitle = "Data from the 2020 American Community Survey (ACS)") +
  labs(fill = "Isolation Index")

ggsave("Black Isolation Index in Richmond.png", Iso_index_cvl_rva)

#Relationshiop btw Rent exploitation and segregation meausres

lm(RentTaxRatio ~ dissim_wb_block, data = cvl_rva_measures_Spatial) #-0.4407
## 
## Call:
## lm(formula = RentTaxRatio ~ dissim_wb_block, data = cvl_rva_measures_Spatial)
## 
## Coefficients:
##     (Intercept)  dissim_wb_block  
##          0.8253          -0.4408
lm(RentTaxRatio ~ iso_b_block, data = cvl_rva_measures_Spatial) #0.3226
## 
## Call:
## lm(formula = RentTaxRatio ~ iso_b_block, data = cvl_rva_measures_Spatial)
## 
## Coefficients:
## (Intercept)  iso_b_block  
##      0.5185       0.3226
cvl_rva_measures_Spatial %>% 
  ggplot(aes(x = dissim_wb_block, y = RentTaxRatio)) +
  geom_point(alpha = 0.3) +
  geom_smooth(method = "lm") +
  facet_wrap(~Region)

cvl_rva_measures_Spatial %>% 
  ggplot(aes(x = iso_b_block, y = RentTaxRatio)) +
  geom_point(alpha = 0.3) +
  geom_smooth(method = "lm") +
  facet_wrap(~Region)

Plots from Previous RMarkdown on distribution

ACS_Housing_Data %>% 
  ggplot(aes(ACS_Housing_Data$PercRentBurdenE, fill = Region)) + 
  geom_histogram()

#distrubtion of the rent tax ratio as a whole
ACS_Housing_Data %>% 
  ggplot(aes(ACS_Housing_Data$RentTaxRatio)) + 
  geom_histogram()

#distrubtion of the rent tax ratio by county
ACS_Housing_Data %>% 
  ggplot(aes(ACS_Housing_Data$RentTaxRatio)) + 
  geom_histogram() +
  facet_wrap(~County)

#distrubtion of the rent tax ratio by county (boxplot)
ACS_Housing_Data |>
  ggplot() +
  aes(x = County, y = RentTaxRatio) +
  geom_boxplot()